from sqlalchemy import select
from forward.dependencies.database import db
from forward.model.schemas.user import UserSchema
from forward.model.tables.user import UserModel


class UserORM:
    @classmethod
    async def get_one_by_id(cls, id: int) -> UserSchema | None:
        statement = select(UserModel).where(UserModel.id == id)
        record = await db.fetch_one(statement)
        if record is None:
            return None
        return UserSchema.model_validate(record, from_attributes=True)
